﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ExpertMIS.Brokers;
using ExpertMIS.Entities;
using ExpertMIS.UserControl;

namespace ExpertMIS.Columns
{
    public partial class Article : System.Web.UI.Page
    {
        protected string ArticleTitle
        {
            get;
            set;
        }

        private void LoadArticle(string OID)
        {
            ADMArticleBroker broker = new ADMArticleBroker();
            broker.UpdateArticleBrowserTimes(OID, 1);

            ADMArticleEntity article = broker.GetArticleByOID(OID);

            if (article == null) return;

            Title = article.Title;
            ArticleTitle = article.Title;
            lblTitle.Text = article.Title;
            lblSource.Text = article.Source;
            lblDate.Text = string.Format("{0:yy-MM-dd}", article.PublishedTime);
            pContent.InnerHtml = article.Content;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadArticle(Request["oid"]);
        }

        protected override void OnPreInit(EventArgs e)
        {
            if (Master is Column)
            {
                (Master as Column).OnLoadLeftPanels += new EventHandler(Article_OnLoadLeftPanels);
            }
        }

        private void Article_OnLoadLeftPanels(object sender, EventArgs e)
        {
            ucBulletinList ucBulletins = LoadControl("~/UserControl/ucBulletinList.ascx") as ucBulletinList;
            if (ucBulletins != null)
            {
                ucBulletins.ShowTitle = true;
                ucBulletins.BulletinCatalog = BulletinCatalog.OrganizationBulletin;
                ucBulletins.LengthVariable = "Article";
                ucBulletins.ShowNewIcon = false;
                (Master as Column).LeftPanel.Controls.Add(ucBulletins);
            }
        }
    }
}
